package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.dao.impl.SupplierDaoImpl;
import com.bw.pojo.Supplier;
import com.bw.pojo.vo.SupplierVo;
import com.bw.service.impl.SupplierServiceImpl;
import com.bw.util.PageResult;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/supplier/*")
public class SupplierController extends BaseController {
    SupplierServiceImpl service = new SupplierServiceImpl();
    protected void getSupplierList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数 2.将json转对象 3.将对象丢给Service 4.响应用户
        String reqInfos = req.getParameter("reqInfos");
        SupplierVo supplierVo = JSONObject.parseObject(reqInfos, SupplierVo.class);
        PageInfo<SupplierVo> pageInfo = service.getSupplierList(supplierVo);
        resp.getWriter().println(JSONObject.toJSONString(pageInfo));
    }
    //下拉
    protected void getSupplier(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Supplier> list = service.getSupplier();
        resp.getWriter().println(JSONObject.toJSONString(list));
    }
    //删除
    protected void getSupplierDel(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        SupplierVo supplierVo = JSONObject.parseObject(reqInfos, SupplierVo.class);
        service.getSupplierDel(supplierVo);
        resp.getWriter().println(JSONObject.toJSONString(200));
    }
}
